from django.db import models


# 题目类型选择（例如选择题、简答题、病例分析题等）
QUESTION_TYPES = (
    ('MCQ', 'Multiple Choice Question'),
    ('SAQ', 'Short Answer Question'),
    ('CAQ', 'Case Analysis Question'),
)

# 学科分类（对应考研的不同学科，如生理学、内科学等）
SUBJECT_CHOICES = (
    ('Physiology', '生理学'),
    ('Biochemistry', '生物化学'),
    # 依次添加其他学科
)

# 练习题模型
class Question(models.Model):
    question_text = models.TextField()
    question_type = models.CharField(max_length=3, choices=QUESTION_TYPES)
    subject = models.CharField(max_length=50, choices=SUBJECT_CHOICES)
    answer = models.TextField()
    explanation = models.TextField()  # 答案解析
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.question_text[:50]  # 显示部分题目内容

# 用户答题记录模型
class UserAnswer(models.Model):
    user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    user_answer = models.TextField()
    is_correct = models.BooleanField(default=False)
    answered_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.user.username} - {self.question.question_text[:30]}"